<?php
include '../connectDatabase.php';

include_once('../is_login.php');
session_start();
if (!is_login()) {
    echo "<script>alert('请登录系统后访问!');window.location.href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/login.php'</script>";
}
if (!is_admin()) {
    echo "<script>alert('权限不足!');window.location.href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/login.php'</script>";
}

$sqlshow = 'select * from users';
$result = mysqli_query($conn, $sqlshow);
$records = array();
while ($record = mysqli_fetch_array($result)) {
    $records[] = $record;
}


//$close = @mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<style type="text/css">
    .title4 {
        color: #fafafa;

        letter-spacing: 0;

        font-size: 50px;

        text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135;

    }

    .box {
        background-color: #FFF;
        border-radius: 5px;
        border: 1px solid #DDD;
        padding: 30px 20px;
        margin: 50px 10% 20px 10%;
        width: 80%;
        height: 400px;
        text-align: center;

    }

    .box:hover {
        box-shadow: 0 0 5px 3px #CCC;
    }

    .table11_7 table {
        width: 100%;
        margin: 15px 0;
        border: 0;
    }

    .table11_7 th {
        background-color: #00A5FF;
        color: #FFFFFF
    }

    .table11_7,
    .table11_7 th,
    .table11_7 td {
        font-size: 0.95em;
        text-align: center;
        padding: 4px;
        border-collapse: collapse;
    }

    .table11_7 th,
    .table11_7 td {
        border: 1px solid #2087fe;
        border-width: 1px 0 1px 0;
        border: 2px inset #ffffff;
    }

    .table11_7 tr {
        border: 1px solid #ffffff;
    }

    .table11_7 tr:nth-child(odd) {
        background-color: #aae1fe;
    }

    .table11_7 tr:nth-child(even) {
        background-color: #ffffff;
    }
</style>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>后台显示新闻类别</title>

    <link rel="stylesheet" href="../../../Public/Css/index.css">
</head>

<body>


    <nav class="navbar">
        <div class="container navbar-content">
            <ul id="menu">
                <li>
                    <a href="http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/login.php"> 首页</a>
                </li>
                <li>
                    <a href=""> 排行</a>
                </li>
                <li>
                    <a href=""> 分类浏览</a>
                </li>
                <li>
                    <a href=""> 所有新闻</a>
                </li>
                <li>
                    <a href=""> 所有新闻</a>
                </li>
                
                <?php
                    session_start();
                    include_once("../is_login.php");
                    if(is_superadmin()){
                        echo "
                        <li>
                        <a href=''>管理功能</a>
                        <ul>
                        <li><a href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/add_admin.php' >添加管理员</a></li>
                        <li><a href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/look_user.php' >浏览用户</a></li>
                        <li><a href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/Search_user.php' >用户查询</a></li>
                        </ul>
                        </li>
                        ";
                    }
                    if(is_jadmin()){
                        echo "
                        <li>
                        <a href=''>管理功能</a>
                        <ul>
                        <li><a href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/look_user.php' >浏览用户</a></li>
                        <li><a href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/Search_user.php' >用户查询</a></li>
                        </ul>
                        </li>
                        ";
                    }

                    if(!is_login()){
                        
                        echo "<li><a href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/login.php'> 登录</a></li>";
                    } else{
                        echo "<li><a href=''>个人信息</a>
                        <ul>
                            <li><a href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/user_modify.php' >修改个人信息</a></li>
                        </ul>
                        </li>";
                        echo "<li><a href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/logout.php'> 注销</a></li>";
                    }
                ?>

        </div><!-- /.container-fluid -->
    </nav>


    <h1 align="center" class="title4">&nbsp;&nbsp;&nbsp;新闻发布系统</h1>

    <div class="box">

        <div class="sign-div">
            <form class="" action="../Action/Search_user_action.php" method="post">
                <h1>用户信息</h1><br />
                <p align="left">
                    搜索: <input class="sign-text" type="text" placeholder="账号" name="ID">
                    <input type="submit" name="submit" value="搜索" />
                </p>
                
                <hr>
            <?php
            echo "<table border=\"10\" width=\"100%\" height=\"50\" cellpadding=5 cellspacing=\"5\"";
            include_once("../connectDatabase.php");
            include_once("../../../Functions/page.php");
            //get_connection();
            $sql = "SELECT * FROM users";
            $result = mysqli_query($conn, $sql);
            $total_records = mysqli_num_rows($result);
            $page_size = 3;
            if(isset($_GET["page_current"])){
                $page_current = $_GET["page_current"];
            }else{
                $page_current = 1;
            }
            $start = ($page_current-1)*$page_size;
            $sql = "SELECT * FROM users order by user_id desc limit $start,$page_size";
            $result = mysqli_query($conn, $sql);
            
            echo "<tr colspan=\"1\"><th>账号</th>";
            echo "<th colspan=\"1\">用户名</th>";
            echo "<th colspan=\"1\">性别</th>";
            echo "<th colspan=\"1\">邮箱</th>";
            echo "<th colspan=\"2\">操作</th></tr>";
            if (mysqli_num_rows($result) > 0) {
                $ID = $_SESSION['userid'];
                    foreach ($records as $row) :
                        if ($row['user_id'] != $ID) {
                            echo "<tr><td> ".$row["user_id"]." </td>";
                            echo "<td> ".$row["user_name"]." </td>";
                            echo "<td> ".$row["user_sex"]." </td>";
                            echo "<td> ".$row["user_email"]." </td>";
                            echo "<td colspan='1'><a href='admin_modify.php?code=".$row['user_id']."'>修改</td>";
                            echo "<td colspan='1'><a href='../Action/delete_admin_action.php?code=".$row['user_id']."'>删除</td>";
                        }
                    endforeach;
            } else {
                echo "<tr><td>暂无用户信息</td><tr>";
            }
            $url = $_SERVER["PHP_SELF"];
            page($total_records-1,$page_size,$page_current,$url,"");
            echo "<br><br>";
            $close = @mysqli_close($conn);
            echo "</table>";
            ?>

            </form>
        </div>
    </div>

    </form>

</body>

</html>